from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.services.bos.bos_client import BosClient
from baidubce.services.bos import storage_class

class BosApi(object):
    def __init__(self, appkey, secretkey, config_dict):
        self.config = config_dict
        self.client = BosClient(
            BceClientConfiguration(
                credentials=BceCredentials(
                    str(appkey),
                    str(secretkey)
                ),
                endpoint=self.config['endpoint']
            )
        )
    
    def __call__(self, imgpath, filename):
        return self.client.put_object_from_file(
                bucket=self.config['bucketname'],
                key=str(filename),
                file_name=str(imgpath),
                storage_class=storage_class.COLD
        )